package com.singleton;

public class SingletonTest {
    private static volatile SingletonTest t;
    private SingletonTest(){}

    public static SingletonTest getInstance(){
        if(t == null) {
            synchronized (SingletonTest.class) {
                if (t == null) {
                    try {
                        Thread.sleep(1);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    t = new SingletonTest();
                }
            }
        }
        return t;
    }

    public void m(){
        System.out.println("m");
    }

    public static void main(String[] args) {
        for(int i = 0; i < 100; i ++){
            new Thread(() -> {
                System.out.println(SingletonTest.getInstance().hashCode());
            }).start();
        }
    }
}
